package com.lam.common.components.easyexcel.handlers;

import java.util.List;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.VerticalAlignment;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;

/**
 * 默认单元格样式
 * @author lam
 *
 */
public class DefaultCellStyleWriteHandler implements CellWriteHandler {
	
	@Override
    public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
            List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//       //不处理表头
		if (!isHead) {
			WriteCellData<?> writeCellData = cellDataList.get(0);
			WriteCellStyle writeCellStyle = writeCellData.getOrCreateStyle();
	        writeCellStyle.setFillPatternType(FillPatternType.NO_FILL);
	        // 设置背景颜色白色
	        //contentWriteCellStyle.setFillForegroundColor(IndexedColors.AUTOMATIC.getIndex());
	        // 设置垂直居中为居中对齐
	        writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	        // 设置左右对齐为靠左对齐
	        writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
	        // 设置单元格上下左右边框为细边框
	        writeCellStyle.setBorderBottom(BorderStyle.THIN);
	        writeCellStyle.setBorderLeft(BorderStyle.THIN);
	        writeCellStyle.setBorderRight(BorderStyle.THIN);
	        writeCellStyle.setBorderTop(BorderStyle.THIN);
	        // 创建字体实例
	        WriteFont cellWriteFont = new WriteFont();
	        // 设置字体大小
	        cellWriteFont.setFontHeightInPoints((short)12);
	        cellWriteFont.setBold(false);
	        writeCellStyle.setWriteFont(cellWriteFont);
		}
    }

	@Override
	public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
			Head head, Integer relativeRowIndex, Boolean isHead) {
	}
	
	@Override
    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
    }

	@Override
	public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
	        WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
	}

}
